home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue29 / s3demo / S3DEMO.ZIP / Scripts.ZIP / PasScript.txt (.txt) < prev    next >
Encoding:
LaTeX Document  |  1997-11-17  |  17.7 KB  |  298 lines

  1.  * TSyntaxMemoParser Script
  2.  * ------------------------
  3.  * Author  :          David Brock
  4.  * Date    :          October 18 1997
  5.  * Language:          Object Pascal
  6. //--------------------------------------------------------------------------------------------------------------------
  7. // Macro definitions. Parameters may be specified and the replacement text terminates with the end of
  8. // line (watch trailing blanks).
  9. #define pt_DEFAULT                  0
  10. #define pt_COMMENT_LINE             1
  11. #define pt_IDENTIFIER               2
  12. #define pt_STRING                   3
  13. #define pt_NUMBER                   4
  14. #define pt_COMMENT                  5
  15. #define pt_HEXNUMBER                6
  16. #define pt_RESERVED                 7
  17. #define pt_COMMENT_BRACE            8
  18. #define pt_COMMENT_STAR             9
  19. #define pt_SYMBOL                   10
  20. #define pt_CHAR_DECIMAL             11
  21. #define pt_CHAR_HEX                 12
  22. #define pt_SEMICOLON                20
  23. #define pt_PROPERTY                 21
  24. #define pt_DEFAULT_TOKEN            22
  25. #define pt_READ                     23
  26. #define pt_WRITE                    24
  27. #define pt_STORED                   25
  28. #define pt_EXPORTS                  26
  29. #define pt_NAME                     27
  30. #define pt_INDEX                    28
  31. #define pt_RESIDENT                 29
  32. #define _non_alpha_                 '[^_A-Za-z0-9]'
  33. #define _all_chars_                 '[\x00-\xFF]'
  34. #define _dec_digit_                 '[0-9]'
  35. #define _hex_digit_                 '[a-fA-F0-9]'
  36. #define _no_chars_                  '[]'
  37. #define _dont_care_                 _all_chars_
  38. #define _DEFAULT_BACKGROUND         clWhite
  39. #define _DEFAULT_FOREGROUND         clBlack
  40. #define ss_PROPERTY                 1
  41. #define ss_EXPORTS                  2
  42. //--------------------------------------------------------------------------------------------------------------------
  43. // %%language section
  44. // Header section. Describes the textual name of the language, case sensitivity and options used by the language.
  45. %%language
  46. Name                      = 'Object Pascal'
  47. Case                      = __INSENSITIVE
  48. Options                   = __DEFAULT_OPTIONS
  49. WordWrapColumn            = _EDGE
  50. Gutter                    = _DEFAULT_GUTTER
  51. Anchor                    = _DEFAULT_START_ANCHOR
  52. ExampleText               = 'program test;\n\
  53.                             \var a: string;\n\
  54.                             \    b: integer;\n\
  55.                             \begin\n\
  56.                             \  b := 0;\n\
  57.                             \  a := \'\';\n\
  58.                             \  while b < 10 do begin\n\
  59.                             \    a := a + IntoToStr(b);\n\
  60.                             \    inc(b);\n\
  61.                             \   end;\n\
  62.                             \end.\n'
  63. EditableStyles              ('Reserved word', pt_RESERVED),
  64.                             ('Comment',       pt_COMMENT),
  65.                             ('Identifier',    pt_IDENTIFIER),
  66.                             ('String',        pt_STRING),
  67.                             ('Number',        pt_NUMBER),
  68.                             ('Symbols',       pt_SYMBOL),
  69.                             ('Default',       pt_DEFAULT)
  70. //--------------------------------------------------------------------------------------------------------------------
  71. // %%words section
  72. // Used to specify simple languge keywords. These are constant value lexemes that always contain the same characters
  73. // and only require the end style to be specified. The words present here will always be tried first. If they fail
  74. // then the entries in the %%tokens section will be allowed to try a match.
  75. // %%words table entries have 3 columns:
  76. //     Column 1          Quoted string giving the characters that make up the word
  77. //     Column 2          Quoted string that specifies how the word is terminated
  78. //     Column 3          Token value returned when word is recognised
  79. %%words
  80. '\/\/'                  _dont_care_                 pt_COMMENT_LINE
  81. '{'                     _dont_care_                 pt_COMMENT_BRACE
  82. '(*'                    _dont_care_                 pt_COMMENT_STAR
  83. ':='                    _dont_care_                 pt_SYMBOL
  84. '+'                     _dont_care_                 pt_SYMBOL
  85. '-'                     _dont_care_                 pt_SYMBOL
  86. '*'                     _dont_care_                 pt_SYMBOL
  87. '\/'                    _dont_care_                 pt_SYMBOL
  88. '='                     _dont_care_                 pt_SYMBOL
  89. '<>'                    _dont_care_                 pt_SYMBOL
  90. '<'                     _dont_care_                 pt_SYMBOL
  91. '>'                     _dont_care_                 pt_SYMBOL
  92. '<='                    _dont_care_                 pt_SYMBOL
  93. '>='                    _dont_care_                 pt_SYMBOL
  94. '('                     _dont_care_                 pt_SYMBOL
  95. ')'                     _dont_care_                 pt_SYMBOL
  96. '['                     _dont_care_                 pt_SYMBOL
  97. ']'                     _dont_care_                 pt_SYMBOL
  98. '.'                     _dont_care_                 pt_SYMBOL
  99. '..'                    _dont_care_                 pt_SYMBOL
  100. '^'                     _dont_care_                 pt_SYMBOL
  101. ','                     _dont_care_                 pt_SYMBOL
  102. ';'                     _dont_care_                 pt_SEMICOLON
  103. ':'                     _dont_care_                 pt_SYMBOL
  104. '@'                     _dont_care_                 pt_SYMBOL
  105. '#'                     _dec_digit_                 pt_CHAR_DECIMAL
  106. '#$'                    _hex_digit_                 pt_CHAR_HEX
  107. 'and'                   _non_alpha_                 pt_RESERVED
  108. 'array'                 _non_alpha_                 pt_RESERVED
  109. 'begin'                 _non_alpha_                 pt_RESERVED
  110. 'case'                  _non_alpha_                 pt_RESERVED
  111. 'const'                 _non_alpha_                 pt_RESERVED
  112. 'div'                   _non_alpha_                 pt_RESERVED
  113. 'do'                    _non_alpha_                 pt_RESERVED
  114. 'downto'                _non_alpha_                 pt_RESERVED
  115. 'else'                  _non_alpha_                 pt_RESERVED
  116. 'end'                   _non_alpha_                 pt_RESERVED
  117. 'false'                 _non_alpha_                 pt_RESERVED
  118. 'file'                  _non_alpha_                 pt_RESERVED
  119. 'for'                   _non_alpha_                 pt_RESERVED
  120. 'forward'               _non_alpha_                 pt_RESERVED
  121. 'function'              _non_alpha_                 pt_RESERVED
  122. 'goto'                  _non_alpha_                 pt_RESERVED
  123. 'if'                    _non_alpha_                 pt_RESERVED
  124. 'in'                    _non_alpha_                 pt_RESERVED
  125. 'label'                 _non_alpha_                 pt_RESERVED
  126. 'mod'                   _non_alpha_                 pt_RESERVED
  127. 'nil'                   _non_alpha_                 pt_RESERVED
  128. 'not'                   _non_alpha_                 pt_RESERVED
  129. 'of'                    _non_alpha_                 pt_RESERVED
  130. 'or'                    _non_alpha_                 pt_RESERVED
  131. 'procedure'             _non_alpha_                 pt_RESERVED
  132. 'program'               _non_alpha_                 pt_RESERVED
  133. 'record'                _non_alpha_                 pt_RESERVED
  134. 'repeat'                _non_alpha_                 pt_RESERVED
  135. 'set'                   _non_alpha_                 pt_RESERVED
  136. 'string'                _non_alpha_                 pt_RESERVED
  137. 'then'                  _non_alpha_                 pt_RESERVED
  138. 'to'                    _non_alpha_                 pt_RESERVED
  139. 'true'                  _non_alpha_                 pt_RESERVED
  140. 'type'                  _non_alpha_                 pt_RESERVED
  141. 'until'                 _non_alpha_                 pt_RESERVED
  142. 'var'                   _non_alpha_                 pt_RESERVED
  143. 'while'                 _non_alpha_                 pt_RESERVED
  144. 'with'                  _non_alpha_                 pt_RESERVED
  145. 'packed'                _non_alpha_                 pt_RESERVED
  146. 'implementation'        _non_alpha_                 pt_RESERVED
  147. 'interface'             _non_alpha_                 pt_RESERVED
  148. 'unit'                  _non_alpha_                 pt_RESERVED
  149. 'uses'                  _non_alpha_                 pt_RESERVED
  150. 'as'                    _non_alpha_                 pt_RESERVED
  151. 'on'                    _non_alpha_                 pt_RESERVED
  152. 'asm'                   _non_alpha_                 pt_RESERVED
  153. 'class'                 _non_alpha_                 pt_RESERVED
  154. 'constructor'           _non_alpha_                 pt_RESERVED
  155. 'destructor'            _non_alpha_                 pt_RESERVED
  156. 'except'                _non_alpha_                 pt_RESERVED
  157. 'exports'               _non_alpha_                 pt_EXPORTS
  158. 'finalization'          _non_alpha_                 pt_RESERVED
  159. 'finally'               _non_alpha_                 pt_RESERVED
  160. 'inherited'             _non_alpha_                 pt_RESERVED
  161. 'initialization'        _non_alpha_                 pt_RESERVED
  162. 'inline'                _non_alpha_                 pt_RESERVED
  163. 'is'                    _non_alpha_                 pt_RESERVED
  164. 'library'               _non_alpha_                 pt_RESERVED
  165. 'object'                _non_alpha_                 pt_RESERVED
  166. 'property'              _non_alpha_                 pt_PROPERTY
  167. 'raise'                 _non_alpha_                 pt_RESERVED
  168. 'shl'                   _non_alpha_                 pt_RESERVED
  169. 'shr'                   _non_alpha_                 pt_RESERVED
  170. 'threadvar'             _non_alpha_                 pt_RESERVED
  171. 'try'                   _non_alpha_                 pt_RESERVED
  172. 'xor'                   _non_alpha_                 pt_RESERVED
  173. 'absolute'              _non_alpha_                 pt_RESERVED
  174. 'abstract'              _non_alpha_                 pt_RESERVED
  175. 'assembler'             _non_alpha_                 pt_RESERVED
  176. 'at'                    _non_alpha_                 pt_RESERVED
  177. 'automated'             _non_alpha_                 pt_RESERVED
  178. 'cdecl'                 _non_alpha_                 pt_RESERVED
  179. 'default'               _non_alpha_                 pt_DEFAULT_TOKEN [ss_PROPERTY]
  180. 'dispid'                _non_alpha_                 pt_RESERVED
  181. 'dynamic'               _non_alpha_                 pt_RESERVED
  182. 'external'              _non_alpha_                 pt_RESERVED
  183. 'index'                 _non_alpha_                 pt_INDEX       [ss_EXPORTS]
  184. 'message'               _non_alpha_                 pt_RESERVED
  185. 'name'                  _non_alpha_                 pt_NAME        [ss_EXPORTS]
  186. 'nodefault'             _non_alpha_                 pt_RESERVED
  187. 'override'              _non_alpha_                 pt_RESERVED
  188. 'pascal'                _non_alpha_                 pt_RESERVED
  189. 'private'               _non_alpha_                 pt_RESERVED
  190. 'protected'             _non_alpha_                 pt_RESERVED
  191. 'public'                _non_alpha_                 pt_RESERVED
  192. 'published'             _non_alpha_                 pt_RESERVED
  193. 'read'                  _non_alpha_                 pt_READ        [ss_PROPERTY]
  194. 'register'              _non_alpha_                 pt_RESERVED
  195. 'resident'              _non_alpha_                 pt_RESIDENT    [ss_EXPORTS]
  196. 'stdcall'               _non_alpha_                 pt_RESERVED
  197. 'stored'                _non_alpha_                 pt_STORED      [ss_PROPERTY]
  198. 'virtual'               _non_alpha_                 pt_RESERVED
  199. 'write'                 _non_alpha_                 pt_WRITE       [ss_PROPERTY]
  200. //--------------------------------------------------------------------------------------------------------------------
  201. // %%handler section
  202. // The %%handler section gives rules to be applied once an entry in the %%words table has been recognised. Normally
  203. // no further processing is required but sometimes a token starts with a fixed set of characters but may be followed
  204. // by a character class rather than a known sequence.
  205. // %%handler table entries have 4 columns:
  206. //     Column 1          Token value to be processed
  207. //     Column 2          Character specifier that follows recognised word
  208. //     Column 3          Quoted string specifying end sequence
  209. //     Column 4          Whether end sequence is part of lexeme
  210. // The <character specifier> is defined as:
  211. //     Column 2          A single character specifier or pre-defined system character macro:
  212. //                         _PASCAL_CHAR         Pascal style character specifier
  213. //                         _C_CHAR              C style character specifier
  214. //                       If the lexeme can optionally have these characters then append '?' to the end
  215. //                       of the quoted string.
  216. //     Column 3          Up to 2 characters may be given as a sequence to terminate the lexeme.
  217. //                       Characters are specified using a simplified regular expression. If this
  218. //                       string is empty then the lexeme will never be matched.
  219. %%handler
  220. pt_COMMENT_LINE         '[^\n]'?                    '\n'           _discard_
  221. pt_COMMENT_BRACE        '[^}]'?                     '}'            _use_
  222. pt_COMMENT_STAR         _all_chars_?                '*)'           _use_
  223. pt_CHAR_DECIMAL         _dec_digit_                 '[^0-9]'       _discard_
  224. pt_CHAR_HEX             _hex_digit_                 '[^a-fA-F0-9]' _discard_
  225. //--------------------------------------------------------------------------------------------------------------------
  226. // %%tokens section
  227. // Used to specify how to recognise non-fixed lexemes. Non-fixed lexemes are only tried if the table entries in the
  228. // %%words section have failed. The non-fixed lexeme is defiened by 5 columns as below:
  229. //     Column 1          Token value
  230. //     Column 2          Single start character specifier
  231. //     Column 3          Single contains character specifier
  232. //     Column 4          End sequence specifier
  233. //     Column 5          Whether end sequence is part of lexeme
  234. // Pre-defined token styles are implemented. If used they should be specified in Column 2. The implemented ones
  235. // are:
  236. //  __STD_PASCALSTRING   Pascal string -- starts with ' ands with ' and uses '' to represent
  237. //                       ' within a string. Does not extend beywond end of line.
  238. //  __STD_IDENTIFIER     Standard identifier. Starts with [_a-zA-Z], contains [_a-zA-Z0-9] and ends with
  239. //                       a non-alpha numeric character that is not part of the lexeme
  240. //  __STD_NUMBER_OR_FP   Integer or floating point constant of syntax:
  241. //                           <Digit String> [ '.' <Digit string> ] [ e|E [+-] <Digit string> ]
  242. %%tokens
  243. pt_HEXNUMBER            '$'                         '[0-9a-fA-F]'       '[^0-9a-fA-F]'        _discard_
  244. pt_STRING               __STD_PASCALSTRING
  245. pt_IDENTIFIER           __STD_IDENTIFIER
  246. pt_NUMBER               __STD_NUMBER_OR_FP
  247. //--------------------------------------------------------------------------------------------------------------------
  248. // %%effects section
  249. // Used to specify the default colors and font styles used for each token
  250. //     Column 1          Token value
  251. //     Column 2          Font styles
  252. //     Column 3          Foreground color
  253. //     Column 4          Background color
  254. //     Column 5          Optional column specifying whether map entry is a 'hotspot'
  255. // Columns 1-4 must be completed for all rows, Column 5 defaults to non-hotspot.
  256. %%effects
  257. pt_DEFAULT              []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  258. pt_IDENTIFIER           []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  259. pt_STRING               [fsItalic]                  _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  260. pt_COMMENT              [fsItalic]                  clBlue                      _DEFAULT_BACKGROUND
  261. pt_RESERVED             [fsBold]                    _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  262. pt_NUMBER               []                          clGreen                     _DEFAULT_BACKGROUND
  263. pt_SYMBOL               []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  264. //--------------------------------------------------------------------------------------------------------------------
  265. // %%map section
  266. // Used to specify which entry in the %%effects table each token value uses. By default all token values map onto
  267. // __DEFAULT_TOKEN which is defined as zero. Table has 2 columns:
  268. //     Column 1          Recognised token value
  269. //     Column 2          Map table entry (i.e. %%effects table entry)
  270. // Normally the %%map table consists of identical value entries.
  271. %%map
  272. pt_IDENTIFIER           pt_IDENTIFIER
  273. pt_STRING               pt_STRING
  274. pt_HEXNUMBER            pt_NUMBER
  275. pt_NUMBER               pt_NUMBER
  276. pt_COMMENT              pt_COMMENT
  277. pt_COMMENT_LINE         pt_COMMENT
  278. pt_COMMENT_STAR         pt_COMMENT
  279. pt_COMMENT_BRACE        pt_COMMENT
  280. pt_RESERVED             pt_RESERVED
  281. pt_SYMBOL               pt_SYMBOL
  282. pt_SEMICOLON            pt_SYMBOL
  283. pt_PROPERTY             pt_RESERVED
  284. pt_READ                 pt_RESERVED
  285. pt_WRITE                pt_RESERVED
  286. pt_DEFAULT_TOKEN        pt_RESERVED
  287. pt_STORED               pt_RESERVED
  288. pt_EXPORTS              pt_RESERVED
  289. pt_NAME                 pt_RESERVED
  290. pt_INDEX                pt_RESERVED
  291. pt_RESIDENT             pt_RESERVED
  292. pt_CHAR_DECIMAL         pt_STRING
  293. pt_CHAR_HEX             pt_STRING
  294. %%states
  295. pt_PROPERTY             (+[ss_PROPERTY])
  296. pt_SEMICOLON            (-[ss_PROPERTY ss_EXPORTS])
  297. pt_EXPORTS              (+[ss_EXPORTS])
  298.